package com.zmn.plat.admin.controller.part.unit;

import java.util.List;
import java.util.stream.Collectors;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zmn.plat.admin.controller.part.PartBaseController;
import com.zmn.plat.model.entity.part.PartSku;
import com.zmn.plat.model.entity.part.PartSkuQuery;
import com.zmn.plat.model.entity.part.PartSkuUnit;

/**
 * 类描述： PartSkuUnitListController
 *
 * @author XiangJunMing
 * @since 2019/05/28 20:36
 */
@Controller
@RequestMapping("/part/unit")
public class PartSkuUnitListController extends PartBaseController {

    private Logger logger = LoggerFactory.getLogger(PartSkuUnitListController.class);

    /**
     * 描述: 跳转到配件单位换算
     *
     * @author XiangJunMing
     * @since 2019/05/28 20:34
     */
    @RequestMapping(value = {"/addEdit"})
    @RequiresPermissions("/part/unit/list.action")
    public String addedit(Model model) {
        List<PartSkuUnit> items = partSkuUnitService.listAll();
        List<Integer> unitSkuIdList = items.stream().map(PartSkuUnit::getSkuId).collect(Collectors.toList());
        PartSkuQuery query = new PartSkuQuery();
        query.setStatus(new Integer(2).shortValue());
        List<PartSku> skus = partSkuService.listByQuery(query).stream().filter(item -> !unitSkuIdList.contains(item.getSkuId()))
            .collect(Collectors.toList());
        model.addAttribute("items", items);
        model.addAttribute("skus", skus);
        return "part/unit/addedit";
    }

}
